# !/usr/bin/python
# -*- coding: UTF-8 -*-
"""
@author: Roc-xb
"""
import requests
from lxml import etree


def run(page=1):
    count = 0
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36'
    }
    params = (
        ('assignee_id', ''),
        ('author_id', ''),
        ('branch', ''),
        ('collaborator_ids', ''),
        ('issue_search', ''),
        ('label_ids', ''),
        ('label_text', ''),
        ('milestone_id', ''),
        ('priority', ''),
        ('private_issue', ''),
        ('program_id', ''),
        ('project_type', ''),
        ('scope', ''),
        ('sort', ''),
        ('state', 'closed'),
        ('target_project', ''),
        ('page', page),
    )

    response = requests.get('https://gitee.com/dromara/hutool/issues', headers=headers, params=params).text
    dom = etree.HTML(response)
    res = dom.xpath('//*[@id="git-issues"]/div/div/div[1]/h3/a/text()')
    if res is None:
        return
    print(page)
    with open("hutool_issus.txt", 'a', encoding="utf-8") as f:
        f.writelines(res)
    next_page = str(dom.xpath('//*[@id="git-discover-page"]/a[@rel="next"]//text()'))
    if len(next_page) > 1:
        run(page + 1)


if __name__ == '__main__':
    run(1)
